window.onload = function(){
    /* 1.怎么实现刷新后回到顶部的事件 */

//《《《《《 函功能数 》》》》》》

    // // 为首页导航加上悬浮事件的效果
	// var mao1 = document.getElementById("mao1")
	// var head_nav = document.getElementById("head_nav")
	
	
	// mao1.onmouseenter = function(){
		
	// 	 addClass(head_nav,"head_show")
	// 	//head_nav.className += " show"
	// }
	// head_nav.onmouseleave = function(){
	// 	// removeClass(head_nav, "show" )
	// 	this.className = "head_nav_sub"
		
    // }
    

    //定义一个参数,添加函数
	function addClass(obj , cn){
		//检查obj中是否有cn
		if(!hasClass(obj , cn)){
			obj.className += " "+cn;
			
		}
		
    }

    console.log(this);
    
    //删除元素中指定的class属性
    
    function removeClass(obj , cn){
		var reg = new RegExp("\\b"+cn+"\\b")
		obj.className = obj.className.replace(reg , "")
    }
    
	//判断obj中是否有cn
	function hasClass(obj , cn){
		//var reg = /\b415\b/;
		var reg = new RegExp("\\b"+cn+"\\b")
		return reg.test(obj.className);
		console.log(reg)
    }
    
//《《《《《《《鼠标滚轮事件》》》》》》》
	//鼠标的滚轮事件
	var comm_topact = document.getElementById("comm-topact")
	var topact_big_img = document.getElementById("topact-big-img")
	var body = document.getElementById("body")
	comm_topact.onmousewheel = function(){
		// alert("gunli")
		event = event || window.event;
        //event.wheelData可以获取鼠标滚轮滚动的方向
        
		// alert(event.wheelDelta);
        // alert(event.detail);
        
		if(event.wheelDelta<0){
			// alert("fesfes")
			topact_big_img.style.zIndex = 0
			addClass(comm_topact,"youxian")
		}else{}
		  		
	}
	//监听刷新后窗口是否在顶部
	window.onscroll = function(){
		if(document.body.scrollTop>=0){
			topact_big_img.style.zIndex = 0
			addClass(comm_topact,"youxian")
		}
	}


// 《《《《《《 轮播图 》》》》》》
var items = document.getElementsByClassName('item'); //图片
var points = document.getElementsByClassName('point'); //点
var goPreBtn = document.getElementById('goPre');
var goNextBtn = document.getElementById('goNext');
// console.log(points)
console.log(points.length)

var index = 0; //index表示第几张图片在展示  ---》第index张图片有active这个类名
// 第几个点在展示 

var clearActive = function(){
    for (var i =0;i<items.length;i++) {
        items[i].className ='item';
    }
    
    for (var i =0;i<points.length;i++) {
        points[i].className ='point';
    }
}

var goindex = function() {
    clearActive();
    // console.log(points)
    points[index].className = 'point active';
    items[index].className = 'item active';
}

var goNext = function() {
    if(index<4){
        index++;
    }else{
        index=0;
    }
    
    goindex();
}

var goPre = function() {
    if(index==0){
        index =4;
    } else {
        index--;
    }
    goindex();
}

// goNextBtn.addEventListener('click',function(){
//     goNext();
// })

// goPreBtn.addEventListener('click',function(){
//     goPre();
// })


for(var i= 0;i<points.length;i++) {
    console.log(i)
    points[i].addEventListener('mouseover',function(){
        console.log('点了')
        // console.log(this);
        var pointIndex =this.getAttribute('data-index');
        // console.log
        // this.getAtt
        // var pointIndex=document.getElementsByClassName("point").getAttribute("data-index");
        console.log(pointIndex)
        index = pointIndex;
        goindex();

    })
}

// 定时器  自动轮播
this.setInterval(goNext,3000);




// 《《《《《《《 新闻公告 》》》》》》》

var first = document.getElementById("first")
var newsitem = document.getElementsByClassName("news_info")
var item_href = document.getElementById("item_href");
// newsitem[1].childNodes[3].innerHTML = "faesfeaw"
/* 	console.log(newsitem[0].childNodes[0].innerHTML)
console.log(newsitem[0].childNodes)
*/	var arr = [
    ["3胜经验卡，随机图标宝箱领取开启",
    "公告","关于英雄联盟4月5日开服的说明","04-01",
    "公告","云顶之奕更新: 星系机制更新","04-01",
    "公告","10.7版本更新公告: 费徳提克重做归来","04-01",
    "公告","银河战争云顶之奕宝典现已开启","03-24",
    "赛事","LPL春季赛4月5日首发 Xiaohu对阵Rookie","04-05",
    "公告","“盟牙有礼”第三周buff掉落中奖公示及活动即将结束公告","03-31",
    ],
    ["关于英雄联盟4月5日开服的说明",
    "公告","4月10日免费英雄联盟更新公告","04-08",
    "公告","英雄时刻功能即将下线","04-03",
    "公告","4月3日不停机版本公告","04-03",
    "新闻","“藏品-炫彩”页签开放测试","04-02",
    "公告","10.7云顶之奕更新：星系机制更新","04-01",
    "公告","10.7版本更新公告：费徳提克重做归来","04-01",
    ],
    ["TES觉醒冲击六连胜 H4cker交手老队友Angel",
    "赛事","LPL赛事没品图：王牌飞行员申请出战","04-08",
    "赛事","LPL春季赛4月8日首发  Smlz交手SwordArT","04-08",
    "娱乐","宅家打比赛!峡谷挑战赛开启报名","03-07",
    "赛事","FPX稳健冲击九连胜 ES能否找回战意","04-07",
    "娱乐","FPX冲击九连胜！DMO与BLG迎来生死战 ES再迎强队挑战","04-07",
    "赛事","LPL春季赛4月7日首发 Flandre对战Khan","04-07",
    ],
    ["【云顶之弈基础答疑向】如何过渡、确定阵容、分装备、D牌上人口",
    "教学","云顶女团强势出道 10.7辛德拉点名秒人","04-07",
    "教学","10.7云顶新晋上分阵容 女武神剑输出爆表","04-06",
    "教学","吸血流巨魔胜率登顶 版本三大冷门套路推荐","04-06",
    "教学","10.7云顶阵容排名 源计划剑士刀妹崛起","04-03",
    "教学","末日重做成新版团战绞肉机 加里奥阿卡丽或将重回巅峰","04-03",
    "教学","银河魔装机神成云顶万金油 机甲暗星刺领衔三套适配阵容","04-02",
    ],
    ["LPL春季赛第五周最佳阵容：TheShy、Rookie齐入选",
    "娱乐","LCK第二轮第二周BP统计：EZ猫咪胜率极低 奥恩退下神坛","04-07",
    "赛事","4月7日LPL海报：FPX“猎杀麒麟”冲击9连胜","04-07",
    "新闻","TES群访QiuQiu：第一局最后一波觉得369还能抢救一下","04-06",
    "赛事","【超凡前瞻】FPX vs LNG：谁能终结小凤凰的八连胜？","04-06",
    "新闻","四大主要联赛全部联盟化，LCK宣布明年进入特许经营","04-06",
    "赛事","S8冠军战队iG正式入驻虎牙直播 4月8日晚7点进行首播","04-06",
    ],
]
// console.log(arr[0])
//定义一个方法用来替换html中的内容
function peidui(num){
    var a = 0 ; var c = -1; ;
    for(i=0;i<arr[num].length;i++){
        var b = arr[num][i];
        if(i==0){
            item_href.innerHTML = b
            
        }else{
            newsitem[a].childNodes[c].innerHTML = b
        }
        c=c+2;
        if(c>5){
            a++;
            c=1;
        }
    }
    
}
//
var part_tab_title = document.getElementById("part_tab_title")
var part_child = part_tab_title.childNodes;
var li1 = document.getElementById("li1")
var li2 = document.getElementById("li2")
var li3 = document.getElementById("li3")
var li4 = document.getElementById("li4")
var li5 = document.getElementById("li5")
li1.onmouseenter = function(){
    peidui(0)
}
li2.onmouseenter = function(){
    peidui(1)
}
li3.onmouseenter = function(){
    peidui(2)
}
li4.onmouseenter = function(){
    peidui(3)
}
li5.onmouseenter = function(){
    peidui(4)
}

/**  侧边栏,监听 **/
var RightNavBar = {
    navBar: null,
    navtitle: null,
    window$: null,
    windowDocument: null,
    init: function() {
        this.windowDocument = $(window.document);
        this.window$ = $(window);
        this.navtitle = $('.rightnav-bar [data-scrollto]');
        this.navBar = $('.rightnav-bar');
        //处理屏幕缩放
        this.window$.on('resize', this.checkShow.bind(this));
        this.checkShow();
        //处理滚动
        this.windowDocument.on('scroll', this.handleScroll.bind(this));
        this.handleScroll();
        //绑定点击导航跳转
        var scrollEl = $('[data-scrollto]');
        scrollEl.on('click', function() {
            var tempThis = $(this);
            var aimEl = $(tempThis.attr('data-scrollto'));
            $('html,body').animate({
                scrollTop: aimEl.offset().top
            }, 200);sh
            RightNavBar.changeTitleClass(tempThis);
        });
        $('.sl_top').on('click', function() {
            $('html,body').animate({
                scrollTop: 0
            });
        });
    },
    handleScroll: function() {
        var scrollTop = this.windowDocument.scrollTop();
        //判断是否可以显示回到顶部
        if (scrollTop > 250) {
            this.navBar.addClass('showTop');
        } else {
            this.navBar.removeClass('showTop');
        }
        //判断标题激活
        var needChangeEl;
        var tempTop;
        for (var i = 0, j = this.navtitle.length; i < j; ++i) {
            tempTop = $(this.navtitle.eq(i).attr('data-scrollto')).offset().top;
            if (scrollTop + this.window$.height() / 2 > tempTop) {
                needChangeEl = this.navtitle.eq(i);
            }
        }
        if (needChangeEl) {
            this.changeTitleClass(needChangeEl);
        } else {
            this.changeTitleClass(null);
        }
    },
    changeTitleClass: function($el) {
        this.navtitle.removeClass('selected');
        $el && $el.addClass('selected');
    },
    checkShow: function() {
        if (this.windowDocument.width() < 1428) {
            this.navBar.removeClass('show');
        } else {
            this.navBar.addClass('show');
        }
    }
};


$(function(){

    $('.rightnav-bar-li').eq(0).click(function(){
        $('html, body').animate({  
              scrollTop: $("#div1").offset().top  
            }, 200); 
    });


    $('.rightnav-bar-li').eq(1).click(function(){
        $('html, body').animate({  
              scrollTop: $("#div2").offset().top  
            }, 200); 
    });
    $('.rightnav-bar-li').eq(2).click(function(){
        $('html, body').animate({  
              scrollTop: $("#div3").offset().top  
            }, 200); 
    });
    $('.rightnav-bar-li').eq(3).click(function(){
        $('html, body').animate({  
              scrollTop: $("#div4").offset().top  
            }, 200); 
    });
    $('.rightnav-bar-li').eq(4).click(function(){
        $('html, body').animate({  
              scrollTop: $("#div5").offset().top  
            }, 200); 
    });
     $(window).scroll(function(){
         if($(window).scrollTop()<588 && $(window).scrollTop()>=0){
         $('.rightnav-bar-li').eq(0).css({background:'red'})
        // console.log(11111);
    }else{
         $('.rightnav-bar-li').eq(0).css({background:'pink'})
    }

    if($(window).scrollTop() >=588 && $(window).scrollTop() < 1156){
         $('.rightnav-bar-li').eq(1).css({background:'red'})
        // console.log(11111);
    }else{
         $('.rightnav-bar-li').eq(1).css({background:'pink'})
    }

    if($(window).scrollTop() >=1156 && $(window).scrollTop() < 1723){
         $('.rightnav-bar-li').eq(2).css({background:'red'})
        // console.log(11111);
    }else{
         $('.rightnav-bar-li').eq(2).css({background:'pink'})
    }
    if($(window).scrollTop() >=1723 && $(window).scrollTop() < 2291){
         $('.rightnav-bar-li').eq(3).css({background:'red'})
        // console.log(11111);
    }else{
         $('.rightnav-bar-li').eq(3).css({background:'pink'})
    }
    if($(window).scrollTop() >=2291 ){
         $('.rightnav-bar-li').eq(4).css({background:'red'})
        // console.log(11111);
    }else{
         $('.rightnav-bar-li').eq(4).css({background:'pink'})
    }
     });

    
    console.log($(window).scrollTop());
    // console.log($(window).scrollHeight());


})


}










